package com.huawei.codearts.controller.v1;

import com.huawei.codearts.service.AsyncService;
import com.huawei.codearts.config.version.ApiVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@ApiVersion(value = 1)
@RestController
@RequestMapping({"api/{version}/test"})
public class TestV1Controller {

    private final AsyncService asyncService;

    @Autowired
    public TestV1Controller(AsyncService asyncService) {
        this.asyncService = asyncService;
    }

    @RequestMapping
    public String index() {
//        int i= 1 / 0;  // 测试异常状态补捕获 通过 AOP @Around 做的捕获
        return "v1 hello world";
    }

    @RequestMapping(value = "/start-task")
    public String startTask() throws InterruptedException {
        asyncService.executeTask();  // 异步执行无需等待
        return "Task started";  // 直接返回
    }

    @RequestMapping(value = "/send")
    public String sendMessage(String message) {
        return "hello send v1";
    }
}
